@extends('layouts.admin')

@section('style')
    <style>
        #page li {
            display: inline-block;
        }

        #page .active span {
            background-color: #009688;
            color: #fff;
            border: 0px;
            height: 30px;
            border-radius: 2px;
        }

        #page .disabled span {
            color: #ccc;
        }
    </style>
@endsection

@section('content')
    <a class="layui-btn" href="{{ route('admin.report.add') }}">添加</a>
    {{--<div class="layui-input-inline" style="padding-left:10px; width: 300px;">
        <input type="tel" name="keywords" id="keywords" lay-verify="required" autocomplete="off" placeholder="手机号/联盟名称" class="layui-input">
    </div>
    <button class="layui-btn search-btn-union" style="padding-left:20px">搜索</button>--}}
    <table class="layui-table">
        <colgroup>
            <col width="50">
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>报告编号</th>
            <th>二维码</th>
            <th>项目位置</th>
            <th>委托方</th>
            <th>总价</th>
            <th>单价</th>
            <th>建成年代</th>
            <th>产权性质</th>
            <th>物理结构</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($reportLists as $reportList)
            <tr>
                <td>{{ $reportList->id }}</td>
                <td>{{ $reportList->number }}</td>
                <td><img src="{{ $reportList->qrcode_image }}"></td>
                <td>{{ $reportList->position }}</td>
                <td>{{ $reportList->client }}</td>
                <td>{{ $reportList->total_price }}</td>
                <td>{{ $reportList->price }}</td>
                <td>{{ $reportList->built_in }}</td>
                <td>{{ $reportList->property_nature }}</td>
                <td>{{ $reportList->is_change == 1 ? '有变化' : '无变化' }}</td>
                <td>
                    <a href="{{ route('admin.report.edit') }}?report_id={{ $reportList->id }}"
                       class="layui-btn layui-btn-sm">编辑</a>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" onclick="changeStatus({{ $reportList->id }})">删除</button>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>

    <div id="page" class="layui-box layui-laypage layui-laypage-default">{{ $reportLists->appends(['keywords' => $keywords])->links() }}</div>
@endsection

@section('script')

    <script>
        $('.search-btn-union').on('click',function(){
            var keywords = $('#keywords').val();
            var url = '/admin/report/index?keywords='+keywords;
            window.location.href = url; //当前窗口打开
        });
        var keywords = $('#keywords').val();

        layui.use(['layer'], function () {
            var layer = layui.layer;
        });
        function changeStatus(report_id) {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                }
            });
            var load = layer.load();
            $.post("{{ route('admin.report.delete') }}", {report_id: report_id},
                function (data) {
                    layer.close(load);
                    if (data.code === 0) {
                        layer.msg('操作成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            window.location.reload();
                        });

                    } else {
                        layer.msg(data.msg, {
                            offset: '15px'
                            , icon: 2
                            , time: 2000
                        });
                    }
                });
        }
    </script>

@endsection